function mdl = slgauss(type, mu, sigma, varargin)
%SLGAUSS Constructs a Gaussian model or an array of Gaussian models
%
% [ Syntax ]
%   - mdl = slgauss(type, mu, sigma, ...)
%   
% [ Arguments ]
%   - type:         The type of Gaussian model
%   - mu:           The mean vector(s)
%   - sigma:        The covariance/variance(s)
%   - mdl:          The constructed model
%
% [ Description ]
%   - mdl = slgauss(type, mu, sigma, ...) constructs a Gaussian model 
%     object of specified type. Currently, three types are available:
%       \{:
%           - 'full':       Gaussian model with full-form covariance.
%                           The object is of class slcfullgauss
%           - 'diag':       Gaussian model with diagonal-form covariance.
%                           The object is of class slcdiaggauss
%           - 'iso':        Gaussian model with isotropic covariance,
%                           The object is of class slcisogauss.
%       \:}
%
%     The form of mu and sigma depends on the specified type. You may
%     refer to the help of slcfullgauss/slcdiaggauss/slcisogauss for
%     details.
%
%     In addition, you can further specify the following properties
%       \{:
%           - 'cachelevel':     the level of pre-computation caching
%                               (by default, it uses the highest level
%                                of the specified type)
%       \:}
%
% [ History ]
%   - Created by Dahua Lin, on Dec 25, 2007
%

%% parse and verify input

error(nargchk(3, inf, nargin));

assert(ischar(type), 'sltoolbox:slgauss:invalidarg', ...
    'type should be a string.');

% options

opts = struct('cachelevel', []);

if nargin >= 4
    opts = slsetopts(opts, varargin{:});
end

assert(isempty(opts.cachelevel) || ...
    (isnumeric(opts.cachelevel) && isscalar(opts.cachelevel) && opts.cachelevel >= 0), ...
    'sltoolbox:slgauss:invalidopt', ...
    'cachelevel should be a nonnegative numeric scalar.');

%% main skeleton

switch type
    case 'full'
        cachelevel = get_cachelevel(opts.cachelevel, 3);
        mdl = slcfullgauss(mu, sigma, cachelevel);
    case 'diag'
        cachelevel = get_cachelevel(opts.cachelevel, 2);
        mdl = slcdiaggauss(mu, sigma, cachelevel);
    case 'iso'
        mdl = slcisogauss(mu, sigma);
    otherwise
        error('sltoolbox:slgauss:invalidarg', ...
            'Unknown gauss model type %s', type);
end


%% Auxiliary function

function c = get_cachelevel(in_c, v0)

if isempty(in_c)
    c = v0;
else
    c = in_c;
end









